package com.adingxiong.quickstart.project.service.impl;

import com.adingxiong.quickstart.project.entity.vo.EchartVo;
import com.adingxiong.quickstart.project.entity.vo.HomeCountVo;
import com.adingxiong.quickstart.project.mapper.EchartMapper;
import com.adingxiong.quickstart.project.service.EchartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName EchartServiceImpl
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/6/11 11:27
 **/
@Service
public class EchartServiceImpl implements EchartService {

    @Autowired
    private EchartMapper echartMapper;

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public List<EchartVo> countGroupByDate(String startDate, String endDate) {
        if(StringUtils.isEmpty(startDate)){
            Calendar cal = Calendar.getInstance();
            cal.set(Calendar.DAY_OF_MONTH,1);
            startDate = sdf.format(cal.getTime());
        }
        if(StringUtils.isEmpty(endDate)){
            endDate = sdf.format(new Date());
        }
        return echartMapper.countGroupByDate(startDate,endDate);
    }

    @Override
    public HomeCountVo getTotal() {
        return echartMapper.getTotal();
    }
}
